package Classic150;

public class Pow {
    /*
        快速幂，分治思想
     */
    public double myPow(double x, int n) {
        if (x == 0.0) return 0.0;
        double res = 1.0;
        long k = n;
        if (k < 0) {
            x = 1 / x;
            k = -k;
        }
        while (k > 0) {
            if ((k % 2) == 1) res *= x;
            x *= x;
            k /= 2;
        }
        return res;
    }
}
